package com.tuoren.forward.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tuoren.forward.entity.Model;
import com.tuoren.forward.entity.req.IdReq;
import com.tuoren.forward.entity.req.ModelSearchReq;
import com.tuoren.forward.service.ModelService;
import com.tuoren.forward.util.Result;
import com.tuoren.forward.util.ResultPage;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping("model")
@Tag(name="设备接口")
public class ModelController {

	@Autowired
	ModelService modelService;
	
	@PostMapping("search")
    @ResponseBody
    @Operation(summary = "查询模型")
	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
	public ResultPage<Model> search(@RequestBody ModelSearchReq req){
		log.info("search>>:{}",req);
		return modelService.search(req);
	}
	
	@PostMapping("add")
    @ResponseBody
    @Operation(summary = "添加模型")
	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
	public Result add(@RequestBody Model req){
		log.info("add>>:{}",req);
		return modelService.add(req);
	}
	
	@PostMapping("edit")
    @ResponseBody
    @Operation(summary = "修改模型")
	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
	public Result edit(@RequestBody Model req){
		log.info("edit>>:{}",req);
		return modelService.edit(req);
	}
	
	@PostMapping("delete")
    @ResponseBody
    @Operation(summary = "删除模型")
	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
	public Result delete(@RequestBody IdReq req){
		log.info("delete>>:{}",req);
		return modelService.delete(req.getId());
	}
}
